package com.zz.ecommerce.declareManage.importB2CDeclareDirect.exchange;

import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.constants.TableConstants;
import com.zz.ecommerce.declareManage.exportB2CDeclare.declareManage.CbecElistDao;
import com.zz.ecommerce.pojo.CbecElist;
import com.zz.ecommerce.pojo.CbecExchangeList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by zhangguowei on 2016/3/28.
 * <p/>
 * 退换货管理
 */
@Controller
@RequestMapping("/importB2CDirect/exchange")
@Scope("prototype")
public class DirectExchangeController {

    @Autowired
    private DirectExchangeFileDao exchangeFileDao;
    @Autowired
    private CbecElistDao cbecElistDao;

    /**
     * 退货申请单生成查询
     *
     * @return
     */
    @RequestMapping(value = "createIndx", method = {RequestMethod.GET})
    public String createIndx() {
        return "declareManage/importB2CDeclareDirect/exchange/exchange_create_indx";
    }

    /**
     * 可退单申请单查询
     *
     * @param cbecElist
     * @param request
     * @return
     */
    @RequestMapping("/queryCreateExchangeList")
    @ResponseBody
    public GridResult queryDeclareList(CbecElist cbecElist, GridRequest request) {
        return new GridResult(cbecElistDao.page(TableConstants.CBEC_ELIST, cbecElist, request.getStart(), request.getEnd(), request.getSortOrder()), request, cbecElistDao.count(TableConstants.CBEC_ELIST, cbecElist));
    }

    /**
     * 退货申请单查询
     *
     * @return
     */
    @RequestMapping(value = "searchIndx", method = {RequestMethod.GET})
    public String searchIndx() {
        return "declareManage/importB2CDeclareDirect/exchange/exchange_search_indx";
    }

    /**
     * 查询申报单列表
     *
     * @param exchangeList
     * @param request
     * @return
     */
    @RequestMapping("/queryExchangeList")
    @ResponseBody
    public GridResult queryExchangeList(CbecExchangeList exchangeList, GridRequest request) {
        int count = exchangeFileDao.count(TableConstants.CBEC_EXCHANGE_LIST, exchangeList);
        List<CbecExchangeList> orderHeadList = exchangeFileDao.page(TableConstants.CBEC_EXCHANGE_LIST, exchangeList,
                request.getStart(), request.getEnd(), request.getSortOrder());
        return new GridResult(orderHeadList, request, count);
    }


}
